﻿using System;

namespace Bricks.Injecting
{

    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TService"></typeparam>
    public class SingleValueResolver<TService> : ValueResolverBase<TService>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="valueAccessor"></param>
        /// <param name="defaultValueAccessor"></param>
        protected SingleValueResolver(Func<TService> valueAccessor, Func<TService> defaultValueAccessor) :
            base(valueAccessor, defaultValueAccessor)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValueAccessor"></param>
        public SingleValueResolver(string key, Func<TService> defaultValueAccessor) :
            this(() => ServiceLocator.Current.Resolve<TService>(key), defaultValueAccessor)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="defaultValueAccessor"></param>
        public SingleValueResolver(Func<TService> defaultValueAccessor) :
            this(string.Empty, defaultValueAccessor)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="defaultValue"></param>
        public SingleValueResolver(TService defaultValue) :
            this(() => defaultValue)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        public SingleValueResolver(string key, TService defaultValue) :
            this(key, () => defaultValue)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        public SingleValueResolver() :
            this(() => default(TService))
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        public SingleValueResolver(string key) :
            this(key, () => default(TService))
        {
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TService"></typeparam>
    /// <typeparam name="TDefault"></typeparam>
    public class SingleValueResolver<TService, TDefault> : SingleValueResolver<TService> where TDefault : TService
    {

        /// <summary>
        /// 
        /// </summary>
        public SingleValueResolver() :
            base(() => ServiceLocator.Current.Resolve<TDefault>())
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        public SingleValueResolver(string key) :
            base(key, () => ServiceLocator.Current.Resolve<TDefault>())
        {
        }
    }
}
